<script setup>

/**
 * 定义emit事件
 */
const emits = defineEmits([
  'sure',
  'cancel',
  'update:modelValue',
])
/**
 * 定义props 属性
 */
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  loading: {
    type: Boolean,
    default: false,
  },
  // 是否显示操作按钮
  showBtn: {
    type: Boolean,
    default: true,
  },
  appendBody: {
    type: Boolean,
    default: true,
  },
  closeModal: {
    type: Boolean,
    default: false,
  },
  destroyClose: {
    type: Boolean,
    default: true,
  },
  cancelTxt: {
    type: String,
    default: '取消'
  },
  sureTxt: {
    type: String,
    default: '确定'
  }
})

/**
 * 接收未使用的属性
 */
const $attrs = useAttrs()

/**
 * 计算弹窗显隐
 */
const visible = computed(
    {
        // getter
        get(){
          return props.modelValue
        },
        // setter
        set(val){
          emits('update:modelValue',val)
        }
    }
)

</script>

<template>
    <el-dialog v-bind="Object.assign($attrs)" v-model="visible" :append-to-body="appendBody" :destroy-on-close="destroyClose" :close-on-click-modal="closeModal">
      <slot></slot>
      <div class="form-btn" v-if="showBtn">
        <el-button size="small"  @click="visible = false;emits('cancel')">{{cancelTxt}}</el-button>
        <el-button type="primary" :loading="loading" size="small" @click="emits('sure')">{{sureTxt}}</el-button>
      </div>
    </el-dialog>
</template>

<style lang="scss">
.el-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0 !important;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
  display: flex;
  flex-direction: column;
  .el-dialog__header {
    // padding: 10px 20px 10px;
    padding: 0 20px;
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #dcdfe6;
    .el-dialog__title {
      line-height: 24px;
      font-size: 14px;
      color: #00a7ff;
      border-left: 5px solid;
      padding-left: 10px;
    }
    .el-dialog__headerbtn {
      // top: 12px;
      // height: 14px;
      top: 0;
      height: 40px;
      width: 15px;
      right: 14px;
      .el-dialog__headerbtn:focus .el-dialog__close, .el-dialog__headerbtn:hover .el-dialog__close {
        color: #00a7ff;
      }
    }
  }
  .el-dialog__body {
    overflow: auto;
    // padding: 10px 20px 20px;
    // padding: 0px;
    padding: 20px 20px 50px 20px;
  }

}

.el-dialog__footer {
  padding: 10px;
}
.el-dialog {
  display: flex;
  display: -ms-flex; /* 兼容IE */
  flex-direction: column;
  -ms-flex-direction: column; /* 兼容IE */
  margin:0 !important;
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  max-height:calc(100% - 30px);
  max-width:calc(100% - 30px);
  // height: 100%;
  // overflow: auto;
}
.el-dialog .el-dialog__body {
  // max-height: 100%;
  flex: 1;
  -ms-flex: 1 1 auto; /* 兼容IE */
  overflow-y: auto;
  overflow-x: hidden;
}

.el-dialog__wrapper {
  /*隐藏ie和edge中遮罩的滚动条*/
  overflow: hidden;
}
.form-btn {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 10px 20px;
  border-top: 1px solid #dcdfe6;
  text-align: right;
  background: #fff;
  z-index: 999;
}
</style>
